import * as React from 'react';
import { Route, Redirect } from 'react-router-dom';

export default function PrivateRoute(route: any) {
  const loggedIn = localStorage.getItem('loggedIn');
  console.log(loggedIn+route.path);
  return (
    <Route
      path={route.path}
      render={props => {
        if (route.title) document.title = route.title;
        console.log("PrivateRoute:"+route.component);
        return loggedIn ? <route.component {...props} routes={route.routes} /> :
          <Redirect {...props} to={{ pathname: '/login', state: { from: props.location } }} />;
      }}
    />
  );
}
